<template>
  <section class="xm-content xm-role">
    <el-form ref="form"
      v-loading="box_loading"
      :model="form" :rules="rules"
      size="mini"
      label-width="100px" inline-message>

      <el-form-item label="重要级别" prop="importanceRank">
        <el-select v-model="form.importanceRank" placeholder="请选择重要级别">
          <el-option :value="0" label="次重要的" />
          <el-option :value="1" label="略重要的" />
          <el-option :value="2" label="重要的" />
          <el-option :value="3" label="很重要的" />
          <el-option :value="4" label="关键的" />
        </el-select>
      </el-form-item>

      <el-form-item label="cp目标" prop="cp">
        <el-input v-model="form.cp" clearable placeholder="请输入cp目标" />
      </el-form-item>
      <el-form-item label="cpk目标" prop="cpk">
        <el-input v-model="form.cpk" clearable placeholder="请输入cpk目标" />
      </el-form-item>
    </el-form>
    <div class="xm-footer">
      <el-button type="primary" size="mini" :loading="btn_loading" @click="saves('form')">确 定</el-button>
      <el-button type="info" size="mini" @click="close">关 闭</el-button>
    </div>
  </section>
</template>

<script>
import {addCpConfigs,editCpConfigs} from '@/api/xapi'
export default {
  props: {
    layerid: {
      default: 0
    },
    row: {
      default: {}
    }
  },
  data() {
    return {
      box_loading: false,
      btn_loading: false,
        form: {
            importanceRank: 0,
            cp: '',
            cpk: '',
        },
      rules: {
          importanceRank: [{ required: true, message: '必填', trigger: 'blur' }],
          cp: [{ required: true, message: '必填', trigger: 'blur' }],
          cpk: [{ required: true, message: '必填', trigger: 'blur' }],
      }
    }
  },
  mounted() {
    if (this.row.id) this.form = JSON.parse(JSON.stringify(this.row))
  },
  methods: {

    /* 添加、编辑 */
    saves(formName) {
        this.$refs[formName].validate(async valid => {
            if (valid) {
                var obj = JSON.parse(JSON.stringify(this.form))
                this.btn_loading = true;
                let res = '';
                if(this.row.id){
                  res = await editCpConfigs(obj)
                }else{
                  res = await addCpConfigs(obj)
                }
                this.btn_loading = false
                if (res.status && res.status != 200) {
                  // this.$message({ message: res.data.message, type: 'error' })
                  return false
                }
                Object.assign(this.$data.form, this.$options.data().form)
                this.$layer.close(this.layerid)
                this.$parent.getList()
                this.$message({ message: '操作成功', type: 'success' })
            } else {
                this.$refs[formName].validate()
            }
        })
    },
    // reset() {
    //   this.$refs.form.resetFields()
    //   // if (this.row.admin_role_id) this.form = JSON.parse(JSON.stringify(this.row))
    // },
    close() {
      this.$layer.close(this.layerid)
    }
  }
}
</script>
<style>
    .el-upload-list__item {
        transition: none !important;
    }
    .custom-tree-node {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 14px;
      padding-right: 8px;
    }
    .el-dialog .el-dialog__footer {
      z-index: 100;
    }
</style>
